home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.8 KB | 71 lines | [TEXT/GEOL] |
- Item 6770862 5-Oct-90 10:43PDT
-
- From: LOCKWOOD Savitar, Mike Lockwood,PRT
-
- To: CPLUS.APPLE$ C++ Interest List--Apple Employees
- CPLUS.DEV$ C++ Interest List--Developers
- MACAPP.TECH$ MacApp Technical
-
- Sub: C++ recursion/polymorphis
-
- Attn: CPlus Apple
- Attn: CPlus Developers
- Attn: MacApp Tech
- SentBy: Mike Lockwood
- Date 10/5/90
- Subject C++ recursion/polymorphism
- From Mike Lockwood
- To CPlus Apple
- CPlus Developers
- MacApp Tech
-
- C++ recursion/polymorphism bug 10:29 AM 10/5/90
- I have found that C++ v 3.1b4 does not properly handle method dispatching when
- the method call is recursive. This problem occurs with PascalObjects
- (descendants of TObject). I have not tried it with C++ style objects.
-
- Here's the scenario: (The classes have been renamed and greatly simplified
- for understandability)
-
- // base class
- class TListItem : public TObject {
-
- TListItem *fNextItem;
-
- virtual pascal void Print(void);
-
- };
-
- // subclass
- class TSpecializedListItem : public TListItem {
-
- virtual pascal void Print(void);
-
- };
-
-
- // offending code
- pascal void TListItem::Print(void)
- {
- // do some printing here
-
- if (fNextItem)
- fNextItem::Print();
- }
-
- The problem is that the call to fNextItem::Print() always calls
- TListItem::Print, even if fNextItem is an instance of TSpecializedListItem!
- The compiler generates a JSR directly to TListItem::Print, rather than going
- to the Pascal style method dispatching routines.
-
- Is this a bug, or a fluke in the C++ language definition? If this is not a
- bug, all the Object Pascal enthusiasts on MacApp.Tech$ hereby have more
- ammunition for their cause!
-
- Hoping not to stir the soup,
-
- Mike Lockwood
-
-
-
-